﻿using System;
using System.Collections.Generic;

namespace SksApp
{
    public class Cache
    {
        private static Cache _instance = null;
        private Cache() { _cache_list = new Dictionary<string, object>(); }
        public static Cache Get
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new Cache();
                }
                return _instance;
            }
        }

        private Dictionary<string, object> _cache_list;

        public T Getir<T>(string key)
        {
            if (_cache_list.ContainsKey(key))
            {
                return (T)Convert.ChangeType(_cache_list[key], typeof(T));
            }
            return (T)Convert.ChangeType(null, typeof(T));
        }

        //public T Getir<T>(string key)
        //{
        //    if (_cache_list.ContainsKey(key))
        //    {
        //        return (T)_cache_list[key];
        //    }
        //    else
        //    {
        //        object obj = null;
        //        return (T)obj;
        //    }
        //}

        public void Yukle<T>(string key, T value)
        {
            if (_cache_list.ContainsKey(key))
            {
                _cache_list[key] = value;
            }
            else
                _cache_list.Add(key, value);
        }

        //public void Yukle(string key, object value)
        //{
        //    if (_cache_list.ContainsKey(key))
        //    {
        //        _cache_list[key] = value;
        //    }
        //    else
        //        _cache_list.Add(key, value);
        //}

        public void Clear()
        {
            _cache_list.Clear();
        }

        public bool Exists(string key)
        {
            return _cache_list.ContainsKey(key);
        }
    }
}
